import java.util.*;

/**
 * @author LKQ
 * @date 2022/6/11 11:24
 * @description
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int N = sc.nextInt();
            int[] data = new int[N];
            for (int i = 0; i < N; i++) {
                data[i] = sc.nextInt();
            }
            Arrays.sort(data);
            int sort = sc.nextInt();
            String result = "";
            if (sort == 0) {
                for (int i = 0; i < N; i++) {
                    result += data[i] + " ";
                }
            } else {
                for (int i = N - 1; i >= 0; i--) {
                    result += data[i] + " ";
                }
            }
            System.out.println(result.substring(0, result.length() - 1));
        }
    }
}
